#include <kutils.h>
#include <string.h>
#include "display.h"
#include "keyboard.h"
#include "syscall.h"
#include "sound.h"

void video_scroll(void);
void set_small_font(void);
void vga_h_resolution(u32int res);

/* These define our textpos32inter, our background and foreground
*  colors (attributes), and x and y cursor coordinates */
u16int *textmemptr;
u32int attrib = 0x0F;
u32int csr_x = 0, csr_y = 0;
u32int ptr_x = 0, ptr_y = 0;
u32int width = 80;
u32int height = 25; 
u32int scroll = 1;

u8int smallfont_thin[256 * 8] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//null
  0x7e, 0x81, 0xa5, 0x81, 0xbd, 0x99, 0x81, 0x7e,//smiley
  0x7e, 0xff, 0xdb, 0xff, 0xc3, 0xe7, 0xff, 0x7e,//inverted smiley
  0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00,//heart
  0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00,//
  0x38, 0x7c, 0x38, 0xfe, 0xfe, 0x7c, 0x38, 0x7c,//
  0x10, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x7c,//
  0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00,//
  0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff,//
  0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00,//
  0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff,//
  0x0f, 0x07, 0x0f, 0x7d, 0xcc, 0xcc, 0xcc, 0x78,//
  0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18,//
  0x3f, 0x33, 0x3f, 0x30, 0x30, 0x70, 0xf0, 0xe0,//
  0x7f, 0x63, 0x7f, 0x63, 0x63, 0x67, 0xe6, 0xc0,//
  0x99, 0x5a, 0x3c, 0xe7, 0xe7, 0x3c, 0x5a, 0x99,//
  0x80, 0xe0, 0xf8, 0xfe, 0xf8, 0xe0, 0x80, 0x00,//
  0x02, 0x0e, 0x3e, 0xfe, 0x3e, 0x0e, 0x02, 0x00,//
  0x18, 0x3c, 0x7e, 0x18, 0x18, 0x7e, 0x3c, 0x18,//
  0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00,//
  0x7f, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x00,//
  0x3e, 0x63, 0x38, 0x6c, 0x6c, 0x38, 0xcc, 0x78,//
  0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x00,//
  0x18, 0x3c, 0x7e, 0x18, 0x7e, 0x3c, 0x18, 0xff,//
  0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x00,//
  0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00,//
  0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00,//
  0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00,//
  0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00,//
  0x00, 0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00,//
  0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x00, 0x00,//
  0x00, 0xff, 0xff, 0x7e, 0x3c, 0x18, 0x00, 0x00,//
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//"space"
  0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x20, 0x00,//!
  0xd8, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//"
  0x50, 0x50, 0xf8, 0x50, 0xf8, 0x50, 0x50, 0x00,//#
  0x20, 0x78, 0xa0, 0x70, 0x28, 0xf0, 0x20, 0x00,//$
  0x42, 0xa4, 0x48, 0x10, 0x24, 0x4a, 0x84, 0x00,//%
  0x20, 0x50, 0x50, 0x20, 0x58, 0x90, 0x68, 0x00,//&
  0x00, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00,//' 
  0x08, 0x10, 0x30, 0x30, 0x30, 0x10, 0x08, 0x00,//( 
  0x20, 0x10, 0x18, 0x18, 0x18, 0x10, 0x20, 0x00,//) 
  0x10, 0x54, 0x38, 0x7c, 0x38, 0x54, 0x10, 0x00,//* 
  0x00, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x00, 0x00,//+ 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x10,//,
  0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00,//- 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,//. 
  0x04, 0x08, 0x08, 0x10, 0x20, 0x20, 0x40, 0x00,//"/"
  0x70, 0x88, 0x98, 0xa8, 0xc8, 0x88, 0x70, 0x00,//0
  0x20, 0x60, 0xa0, 0x20, 0x20, 0x20, 0xf8, 0x00,//1
  0x70, 0x88, 0x08, 0x30, 0x40, 0x80, 0xf8, 0x00,//2
  0x70, 0x88, 0x08, 0x30, 0x08, 0x88, 0x70, 0x00,//3
  0x10, 0x90, 0x90, 0x90, 0xf8, 0x10, 0x10, 0x00,//4
  0xf0, 0x80, 0x80, 0xf0, 0x08, 0x08, 0xf0, 0x00,//5
  0x70, 0x88, 0x80, 0xf0, 0x88, 0x88, 0x70, 0x00,//6
  0xf8, 0x88, 0x10, 0x10, 0x20, 0x20, 0x20, 0x00,//7
  0x70, 0x88, 0x88, 0x70, 0x88, 0x88, 0x70, 0x00,//8
  0x70, 0x88, 0x88, 0x78, 0x08, 0x08, 0x70, 0x00,//9
  0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00,//:
  0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x20, 0x40,//;
  0x00, 0x04, 0x18, 0x60, 0x18, 0x04, 0x00, 0x00,//<
  0x00, 0x00, 0x7c, 0x00, 0x00, 0x7c, 0x00, 0x00,//=
  0x00, 0x20, 0x18, 0x06, 0x18, 0x20, 0x00, 0x00,//>
  0x30, 0x48, 0x08, 0x10, 0x20, 0x00, 0x20, 0x00,//?
  0x7c, 0x82, 0x9a, 0xaa, 0xaa, 0x9c, 0x80, 0x7e,//@
  0x10, 0x28, 0x44, 0x44, 0x7c, 0x44, 0x44, 0x00,//A
  0x78, 0x44, 0x44, 0x78, 0x44, 0x44, 0x78, 0x00,//B
  0x38, 0x44, 0x40, 0x40, 0x40, 0x44, 0x38, 0x00,//C
  0x70, 0x48, 0x44, 0x44, 0x44, 0x48, 0x70, 0x00,//D
  0x7c, 0x40, 0x40, 0x78, 0x40, 0x40, 0x7c, 0x00,//E
  0x7c, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x00,//F
  0x38, 0x44, 0x40, 0x4c, 0x44, 0x44, 0x38, 0x00,//G
  0x44, 0x44, 0x44, 0x7c, 0x44, 0x44, 0x44, 0x00,//H
  0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00,//I
  0x1c, 0x08, 0x08, 0x08, 0x48, 0x48, 0x30, 0x00,//J
  0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x00,//K
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7c, 0x00,//L
  0x44, 0x6c, 0x54, 0x54, 0x44, 0x44, 0x44, 0x00,//M
  0x44, 0x64, 0x64, 0x54, 0x4c, 0x4c, 0x44, 0x00,//N
  0x38, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00,//O
  0x78, 0x44, 0x44, 0x78, 0x40, 0x40, 0x40, 0x00,//P
  0x38, 0x44, 0x44, 0x44, 0x54, 0x48, 0x34, 0x00,//Q
  0x78, 0x44, 0x44, 0x78, 0x50, 0x48, 0x44, 0x00,//R
  0x38, 0x44, 0x40, 0x38, 0x04, 0x44, 0x38, 0x00,//S
  0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00,//T
  0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00,//U
  0x44, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x00,//V
  0x44, 0x44, 0x44, 0x54, 0x54, 0x28, 0x28, 0x00,//W
  0x44, 0x44, 0x28, 0x10, 0x28, 0x44, 0x44, 0x00,//X
  0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x10, 0x00,//Y
  0x7c, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7c, 0x00,//Z
  0x1c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1c, 0x00,//[ 
  0x40, 0x20, 0x20, 0x10, 0x08, 0x08, 0x04, 0x00,//"\"
  0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00,//]
  0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,//^
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,//_
  0x00, 0x20, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00,//`
  0x00, 0x00, 0x78, 0x88, 0x88, 0x88, 0x74, 0x00,//a
  0x40, 0x40, 0x40, 0x78, 0x44, 0x44, 0x78, 0x00,//b
  0x00, 0x00, 0x70, 0x88, 0x80, 0x88, 0x70, 0x00,//c
  0x08, 0x08, 0x08, 0x78, 0x88, 0x88, 0x78, 0x00,//d
  0x00, 0x00, 0x70, 0x88, 0xf8, 0x80, 0x70, 0x00,//e
  0x10, 0x28, 0x20, 0x70, 0x20, 0x20, 0x20, 0x00,//f
  0x00, 0x00, 0x70, 0x88, 0x88, 0x78, 0x08, 0x70,//g
  0x80, 0x80, 0x80, 0xe0, 0x90, 0x90, 0x90, 0x00,//h
  0x00, 0x20, 0x00, 0x20, 0x20, 0x20, 0x20, 0x00,//i
  0x00, 0x10, 0x00, 0x10, 0x10, 0x10, 0x90, 0x60,//j
  0x80, 0x80, 0x90, 0xa0, 0xc0, 0xa0, 0x90, 0x00,//k
  0x40, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x00,//l
  0x00, 0x00, 0xd0, 0xa8, 0xa8, 0xa8, 0xa8, 0x00,//m
  0x00, 0x00, 0xb0, 0x48, 0x48, 0x48, 0x48, 0x00,//n
  0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x70, 0x00,//o
  0x00, 0x00, 0x70, 0x48, 0x48, 0x70, 0x40, 0x40,//p
  0x00, 0x00, 0x60, 0x90, 0x90, 0x70, 0x10, 0x18,//q
  0x00, 0x00, 0xa0, 0xd0, 0x80, 0x80, 0x80, 0x00,//r
  0x00, 0x00, 0x70, 0x80, 0x60, 0x10, 0xe0, 0x00,//s
  0x00, 0x40, 0xf0, 0x40, 0x40, 0x40, 0x30, 0x00,//t
  0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x68, 0x00,//u
  0x00, 0x00, 0x88, 0x88, 0x50, 0x50, 0x20, 0x00,//v
  0x00, 0x00, 0x88, 0x88, 0xa8, 0x50, 0x50, 0x00,//w
  0x00, 0x00, 0x88, 0x50, 0x20, 0x50, 0x88, 0x00,//x
  0x00, 0x00, 0x88, 0x50, 0x50, 0x20, 0x20, 0x40,//y
  0x00, 0x00, 0xf8, 0x10, 0x20, 0x40, 0xf8, 0x00,//z
  0x04, 0x08, 0x08, 0x10, 0x08, 0x08, 0x04, 0x00,//{
  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00,//|
  0x20, 0x10, 0x10, 0x08, 0x10, 0x10, 0x20, 0x00,//}
  0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x00, 0x00,//~
  0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0x00,
  0x78, 0xcc, 0xc0, 0xcc, 0x78, 0x18, 0x0c, 0x78,
  0x00, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0x7e, 0x00,
  0x1c, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00,
  0x7e, 0xc3, 0x3c, 0x06, 0x3e, 0x66, 0x3f, 0x00,
  0xcc, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x7e, 0x00,
  0xe0, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x7e, 0x00,
  0x30, 0x30, 0x78, 0x0c, 0x7c, 0xcc, 0x7e, 0x00,
  0x00, 0x00, 0x78, 0xc0, 0xc0, 0x78, 0x0c, 0x38,//unknown
  0x7e, 0xc3, 0x3c, 0x66, 0x7e, 0x60, 0x3c, 0x00,
  0xcc, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00,
  0xe0, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00,
  0xcc, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00,
  0x7c, 0xc6, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00,
  0xe0, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00,
  0xc6, 0x38, 0x6c, 0xc6, 0xfe, 0xc6, 0xc6, 0x00,
  0x30, 0x30, 0x00, 0x78, 0xcc, 0xfc, 0xcc, 0x00,
  0x1c, 0x00, 0xfc, 0x60, 0x78, 0x60, 0xfc, 0x00,
  0x00, 0x00, 0x7f, 0x0c, 0x7f, 0xcc, 0x7f, 0x00,
  0x3e, 0x6c, 0xcc, 0xfe, 0xcc, 0xcc, 0xce, 0x00,
  0x78, 0xcc, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00,
  0x00, 0xcc, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00,
  0x00, 0xe0, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00,
  0x78, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0x7e, 0x00,
  0x00, 0xe0, 0x00, 0xcc, 0xcc, 0xcc, 0x7e, 0x00,
  0x00, 0xcc, 0x00, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8,//y umlaut
  0xc3, 0x18, 0x3c, 0x66, 0x66, 0x3c, 0x18, 0x00,
  0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00,
  0x18, 0x18, 0x7e, 0xc0, 0xc0, 0x7e, 0x18, 0x18,
  0x38, 0x6c, 0x64, 0xf0, 0x60, 0xe6, 0xfc, 0x00,
  0xcc, 0xcc, 0x78, 0xfc, 0x30, 0xfc, 0x30, 0x30,
  0xf8, 0xcc, 0xcc, 0xfa, 0xc6, 0xcf, 0xc6, 0xc7,
  0x0e, 0x1b, 0x18, 0x3c, 0x18, 0x18, 0xd8, 0x70,
  0x1c, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x7e, 0x00,
  0x38, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00,
  0x00, 0x1c, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00,
  0x00, 0x1c, 0x00, 0xcc, 0xcc, 0xcc, 0x7e, 0x00,
  0x00, 0xf8, 0x00, 0xf8, 0xcc, 0xcc, 0xcc, 0x00,
  0xfc, 0x00, 0xcc, 0xec, 0xfc, 0xdc, 0xcc, 0x00,
  0x3c, 0x6c, 0x6c, 0x3e, 0x00, 0x7e, 0x00, 0x00,
  0x38, 0x6c, 0x6c, 0x38, 0x00, 0x7c, 0x00, 0x00,
  0x30, 0x00, 0x30, 0x60, 0xc0, 0xcc, 0x78, 0x00,
  0x00, 0x00, 0x00, 0xfc, 0xc0, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0c, 0x00, 0x00,
  0xc3, 0xc6, 0xcc, 0xde, 0x33, 0x66, 0xcc, 0x0f,
  0xc3, 0xc6, 0xcc, 0xdb, 0x37, 0x6f, 0xcf, 0x03,
  0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00,
  0x00, 0x33, 0x66, 0xcc, 0x66, 0x33, 0x00, 0x00,
  0x00, 0xcc, 0x66, 0x33, 0x66, 0xcc, 0x00, 0x00,
  0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88,
  0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa,
  0xdb, 0x77, 0xdb, 0xee, 0xdb, 0x77, 0xdb, 0xee,
  0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
  0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18,
  0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18,
  0x36, 0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36,
  0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36,
  0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18,
  0x36, 0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36,
  0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  0x00, 0x00, 0xfe, 0x06, 0xf6, 0x36, 0x36, 0x36,
  0x36, 0x36, 0xf6, 0x06, 0xfe, 0x00, 0x00, 0x00,
  0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00,
  0x18, 0x18, 0xf8, 0x18, 0xf8, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18,
  0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00,
  0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18,
  0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18,
  0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
  0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18,
  0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18,
  0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36,
  0x36, 0x36, 0x37, 0x30, 0x3f, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x3f, 0x30, 0x37, 0x36, 0x36, 0x36,
  0x36, 0x36, 0xf7, 0x00, 0xff, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36,
  0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36,
  0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
  0x36, 0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36,
  0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
  0x36, 0x36, 0x36, 0x36, 0xff, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18,
  0x00, 0x00, 0x00, 0x00, 0xff, 0x36, 0x36, 0x36,
  0x36, 0x36, 0x36, 0x36, 0x3f, 0x00, 0x00, 0x00,
  0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18,
  0x00, 0x00, 0x00, 0x00, 0x3f, 0x36, 0x36, 0x36,
  0x36, 0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36,
  0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18,
  0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
  0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
  0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
  0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x76, 0xdc, 0xc8, 0xdc, 0x76, 0x00,
  0x00, 0x78, 0xcc, 0xf8, 0xcc, 0xf8, 0xc0, 0xc0,
  0x00, 0xfc, 0xcc, 0xc0, 0xc0, 0xc0, 0xc0, 0x00,
  0x00, 0xfe, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00,
  0xfc, 0xcc, 0x60, 0x30, 0x60, 0xcc, 0xfc, 0x00,
  0x00, 0x00, 0x7e, 0xd8, 0xd8, 0xd8, 0x70, 0x00,
  0x00, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0xc0,
  0x00, 0x76, 0xdc, 0x18, 0x18, 0x18, 0x18, 0x00,
  0xfc, 0x30, 0x78, 0xcc, 0xcc, 0x78, 0x30, 0xfc,
  0x38, 0x6c, 0xc6, 0xfe, 0xc6, 0x6c, 0x38, 0x00,
  0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x6c, 0xee, 0x00,
  0x1c, 0x30, 0x18, 0x7c, 0xcc, 0xcc, 0x78, 0x00,
  0x00, 0x00, 0x7e, 0xdb, 0xdb, 0x7e, 0x00, 0x00,
  0x06, 0x0c, 0x7e, 0xdb, 0xdb, 0x7e, 0x60, 0xc0,
  0x38, 0x60, 0xc0, 0xf8, 0xc0, 0x60, 0x38, 0x00,
  0x78, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00,
  0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0x00,
  0x30, 0x30, 0xfc, 0x30, 0x30, 0x00, 0xfc, 0x00,
  0x60, 0x30, 0x18, 0x30, 0x60, 0x00, 0xfc, 0x00,
  0x18, 0x30, 0x60, 0x30, 0x18, 0x00, 0xfc, 0x00,
  0x0e, 0x1b, 0x1b, 0x18, 0x18, 0x18, 0x18, 0x18,
  0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0x70,
  0x30, 0x30, 0x00, 0xfc, 0x00, 0x30, 0x30, 0x00,
  0x00, 0x76, 0xdc, 0x00, 0x76, 0xdc, 0x00, 0x00,
  0x38, 0x6c, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
  0x0f, 0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x3c, 0x1c,
  0x78, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00,
  0x70, 0x18, 0x30, 0x60, 0x78, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

u8int smallfont_thick[256 * 8] =
{
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E,
	0x7E, 0xFF, 0xDB, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E,
	0x6C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10, 0x00,
	0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00,
	0x38, 0x7C, 0x38, 0xFE, 0xFE, 0x92, 0x10, 0x7C,
	0x00, 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x7C,
	0x00, 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x00, 0x00,
	0xFF, 0xFF, 0xE7, 0xC3, 0xC3, 0xE7, 0xFF, 0xFF,
	0x00, 0x3C, 0x66, 0x42, 0x42, 0x66, 0x3C, 0x00,
	0xFF, 0xC3, 0x99, 0xBD, 0xBD, 0x99, 0xC3, 0xFF,
	0x0F, 0x07, 0x0F, 0x7D, 0xCC, 0xCC, 0xCC, 0x78,
	0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18,
	0x3F, 0x33, 0x3F, 0x30, 0x30, 0x70, 0xF0, 0xE0,
	0x7F, 0x63, 0x7F, 0x63, 0x63, 0x67, 0xE6, 0xC0,
	0x99, 0x5A, 0x3C, 0xE7, 0xE7, 0x3C, 0x5A, 0x99,
	0x80, 0xE0, 0xF8, 0xFE, 0xF8, 0xE0, 0x80, 0x00,
	0x02, 0x0E, 0x3E, 0xFE, 0x3E, 0x0E, 0x02, 0x00,
	0x18, 0x3C, 0x7E, 0x18, 0x18, 0x7E, 0x3C, 0x18, 
	0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00, 
	0x7F, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x00, 
	0x3E, 0x63, 0x38, 0x6C, 0x6C, 0x38, 0x86, 0xFC, 
	0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x7E, 0x00, 
	0x18, 0x3C, 0x7E, 0x18, 0x7E, 0x3C, 0x18, 0xFF,
	0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00,
	0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00,
	0x00, 0x18, 0x0C, 0xFE, 0x0C, 0x18, 0x00, 0x00, 
	0x00, 0x30, 0x60, 0xFE, 0x60, 0x30, 0x00, 0x00, 
	0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, 0x00, 
	0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00, 
	0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x00, 0x00, 
	0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00,
	0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x6C, 0x6C, 0xFE, 0x6C, 0xFE, 0x6C, 0x6C, 0x00, 
	0x18, 0x7E, 0xC0, 0x7C, 0x06, 0xFC, 0x18, 0x00, 
	0x00, 0xC6, 0xCC, 0x18, 0x30, 0x66, 0xC6, 0x00,
	0x38, 0x6C, 0x38, 0x76, 0xDC, 0xCC, 0x76, 0x00,
	0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00, 
	0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00,
	0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, 
	0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30,
	0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00,
	0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x00,
	0x7C, 0xCE, 0xDE, 0xF6, 0xE6, 0xC6, 0x7C, 0x00, 
	0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xFC, 0x00, 
	0x78, 0xCC, 0x0C, 0x38, 0x60, 0xCC, 0xFC, 0x00, 
	0x78, 0xCC, 0x0C, 0x38, 0x0C, 0xCC, 0x78, 0x00, 
	0x1C, 0x3C, 0x6C, 0xCC, 0xFE, 0x0C, 0x1E, 0x00, 
	0xFC, 0xC0, 0xF8, 0x0C, 0x0C, 0xCC, 0x78, 0x00, 
	0x38, 0x60, 0xC0, 0xF8, 0xCC, 0xCC, 0x78, 0x00,
	0xFC, 0xCC, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x00,
	0x78, 0xCC, 0xCC, 0x78, 0xCC, 0xCC, 0x78, 0x00, 
	0x78, 0xCC, 0xCC, 0x7C, 0x0C, 0x18, 0x70, 0x00, 
	0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 
	0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x30, 
	0x18, 0x30, 0x60, 0xC0, 0x60, 0x30, 0x18, 0x00, 
	0x00, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00, 0x00, 
	0x60, 0x30, 0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 0x30, 0x30, 0x78, 0x00,
	0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x00, 
	0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00,
	0xC6, 0xC6, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, 
	0xC6, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0xC6, 0x00, 
	0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x30, 0x78, 0x00,
	0xFE, 0xC6, 0x8C, 0x18, 0x32, 0x66, 0xFE, 0x00,
	0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00,
	0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x02, 0x00,
	0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00, 
	0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 
	0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, 
	0xE0, 0x60, 0x60, 0x7C, 0x66, 0x66, 0xDC, 0x00, 
	0x00, 0x00, 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x00,
	0x1C, 0x0C, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00,
	0x00, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, 
	0x38, 0x6C, 0x64, 0xF0, 0x60, 0x60, 0xF0, 0x00, 
	0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, 
	0xE0, 0x60, 0x6C, 0x76, 0x66, 0x66, 0xE6, 0x00, 
	0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, 
	0x0C, 0x00, 0x1C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, 
	0xE0, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0xE6, 0x00,
	0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, 
	0x00, 0x00, 0xCC, 0xFE, 0xFE, 0xD6, 0xD6, 0x00, 
	0x00, 0x00, 0xB8, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, 
	0x00, 0x00, 0x78, 0xCC, 0xCC, 0xCC, 0x78, 0x00, 
	0x00, 0x00, 0xDC, 0x66, 0x66, 0x7C, 0x60, 0xF0, 
	0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0x1E, 
	0x00, 0x00, 0xDC, 0x76, 0x62, 0x60, 0xF0, 0x00, 
	0x00, 0x00, 0x7C, 0xC0, 0x70, 0x1C, 0xF8, 0x00,
	0x10, 0x30, 0xFC, 0x30, 0x30, 0x34, 0x18, 0x00, 
	0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 
	0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00, 
	0x00, 0x00, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, 
	0x00, 0x00, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0x00, 
	0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, 
	0x00, 0x00, 0xFC, 0x98, 0x30, 0x64, 0xFC, 0x00,
	0x1C, 0x30, 0x30, 0xE0, 0x30, 0x30, 0x1C, 0x00, 
	0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, 
	0xE0, 0x30, 0x30, 0x1C, 0x30, 0x30, 0xE0, 0x00, 
	0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0x00,
	0x7C, 0xC6, 0xC0, 0xC6, 0x7C, 0x0C, 0x06, 0x7C, 
	0x00, 0xCC, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00,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0x00, 0xCC, 0x66, 0x33, 0x66, 0xCC, 0x00, 0x00, 
	0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88,
	0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 
	0xDB, 0xF6, 0xDB, 0x6F, 0xDB, 0x7E, 0xD7, 0xED, 
	0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
	0x18, 0x18, 0x18, 0x18, 0xF8, 0x18, 0x18, 0x18,
	0x18, 0x18, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18,
	0x36, 0x36, 0x36, 0x36, 0xF6, 0x36, 0x36, 0x36,
	0x00, 0x00, 0x00, 0x00, 0xFE, 0x36, 0x36, 0x36, 
	0x00, 0x00, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, 
	0x36, 0x36, 0xF6, 0x06, 0xF6, 0x36, 0x36, 0x36, 
	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 
	0x00, 0x00, 0xFE, 0x06, 0xF6, 0x36, 0x36, 0x36, 
	0x36, 0x36, 0xF6, 0x06, 0xFE, 0x00, 0x00, 0x00, 
	0x36, 0x36, 0x36, 0x36, 0xFE, 0x00, 0x00, 0x00,
	0x18, 0x18, 0xF8, 0x18, 0xF8, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0xF8, 0x18, 0x18, 0x18, 
	0x18, 0x18, 0x18, 0x18, 0x1F, 0x00, 0x00, 0x00, 
	0x18, 0x18, 0x18, 0x18, 0xFF, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xFF, 0x18, 0x18, 0x18, 
	0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x18, 0x18, 
	0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 
	0x18, 0x18, 0x18, 0x18, 0xFF, 0x18, 0x18, 0x18,
	0x18, 0x18, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, 
	0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, 
	0x36, 0x36, 0x37, 0x30, 0x3F, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x3F, 0x30, 0x37, 0x36, 0x36, 0x36, 
	0x36, 0x36, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0xFF, 0x00, 0xF7, 0x36, 0x36, 0x36, 
	0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 
	0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00,
	0x36, 0x36, 0xF7, 0x00, 0xF7, 0x36, 0x36, 0x36, 
	0x18, 0x18, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 
	0x36, 0x36, 0x36, 0x36, 0xFF, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0xFF, 0x00, 0xFF, 0x18, 0x18, 0x18, 
	0x00, 0x00, 0x00, 0x00, 0xFF, 0x36, 0x36, 0x36, 
	0x36, 0x36, 0x36, 0x36, 0x3F, 0x00, 0x00, 0x00, 
	0x18, 0x18, 0x1F, 0x18, 0x1F, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, 
	0x00, 0x00, 0x00, 0x00, 0x3F, 0x36, 0x36, 0x36, 
	0x36, 0x36, 0x36, 0x36, 0xFF, 0x36, 0x36, 0x36,
	0x18, 0x18, 0xFF, 0x18, 0xFF, 0x18, 0x18, 0x18, 
	0x18, 0x18, 0x18, 0x18, 0xF8, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x1F, 0x18, 0x18, 0x18, 
	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
	0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 
	0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
	0x0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18, 0x18,
	0x18, 0x18, 0x18, 0x18, 0x18, 0xD8, 0xD8, 0x70,
	0x18, 0x18, 0x00, 0x7E, 0x00, 0x18, 0x18, 0x00,
	0x00, 0x76, 0xDC, 0x00, 0x76, 0xDC, 0x00, 0x00,
	0x38, 0x6C, 0x6C, 0x38, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
	0x0F, 0x0C, 0x0C, 0x0C, 0xEC, 0x6C, 0x3C, 0x1C,
	0x58, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00,
	0x70, 0x98, 0x30, 0x60, 0xF8, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

/* Scrolls the screen */
void video_scroll(void)
{
	u32int blank, temp;
	blank = 0x20 | (attrib << 8);

	if(ptr_y >= height)
	{
		if(scroll)
		{
			temp = ptr_y - height + 1;
			memcpy(textmemptr, textmemptr + temp * width, (size_t)((height - temp) * width * 2));
			memsetw(textmemptr + (height - temp) * width, (u16int)blank, (size_t)width);
		}
		ptr_y = height - 1;
	}
}

void set_cursor(u32int x, u32int y)
{
	if(x < width)
		csr_x = x; 
	if(y < height)	
		csr_y = y;
	update_cursor();
}

void set_pointer(u32int x, u32int y)
{
	if(x < width)
		ptr_x = x; 
	if(y < height)	
		ptr_y = y;
}

u32int get_cursor_x(void)
{
	return csr_x;
}

u32int get_cursor_y(void)
{
	return csr_y;
}

u32int get_pointer_x(void)
{
	return ptr_x;
}

u32int get_pointer_y(void)
{
	return ptr_y;
}

void enable_scroll(void)
{
	scroll = 1;
}

void disable_scroll(void)
{
	scroll = 0;
}

void update_cursor(void)
{
	u32int temp;
    temp = csr_y * width + csr_x;

    outportb(CRT_ADDR, CRT_I_CUR_LOC_H);
    outportb(CRT_DATA, (u8int)(temp >> 8));
    outportb(CRT_ADDR, CRT_I_CUR_LOC_L);
    outportb(CRT_DATA, (u8int)temp);
}

/* Clears the screen */
void clear_screen(void)
{
    u32int blank;
    u32int i;
    blank = 0x20 | (attrib << 8);
    for(i = 0; i < height; i++)
        memsetw(textmemptr + i * width, (u16int)blank, (size_t)width);
}

void write_char(u8int c)
{
	if(c == 0x07)
	{
		write_string("beep");
		beep(1000, 1, 10, 0);
	}
    // Handle a backspace, by moving the cursor back one space, writing a blank, and moving back again
    else if(c == 0x08)
    {
    	if(ptr_x != 0) ptr_x--;//move it back
		write_char(' ');//write a blank s8intacter
		if(ptr_x != 0) ptr_x--;//move it back
    }
    /* Handles a tab by incrementing the cursor's x, but only
    *  to a pos32int that will make it divisible by 8 */
    else if(c == 0x09)
    {
        ptr_x = (ptr_x + 8) & ~(8 - 1);
    }
    /* Handles a 'Carriage Return', which simply brings the
    *  cursor back to the margin */
    else if(c == '\r')
    {
        ptr_x = 0;
    }
    /* We handle our newlines the way DOS and the BIOS do: we
    *  treat it as if a 'CR' was also there, so we bring the
    *  cursor to the margin and we increment the 'y' value */
    else if(c == '\n')
    {
        ptr_x = 0;
        ptr_y++;
    }
    /* Any s8intacter greater than and including a space, is a
    *  prs32intable s8intacter. The equation for finding the index
    *  in a linear chunk of memory can be represented by:
    *  Index = [(y * width) + x] */
    else if(c >= ' ')
    {
       poke_s8int(c);
			ptr_x++;
    }

    /* If the cursor has reached the edge of the screen's width, we
    *  insert a new line in there */
    if(ptr_x >= width)
    {
        ptr_x = 0;
        ptr_y++;
    }
	
	video_scroll();
}

//pokes a raw s8intacter s32into the screen without advancing the cursor or handling special s8intacters
void poke_s8int(u8int c)
{
	u16int *where;
	u32int att = attrib << 8;

	if(c >= ' ')
   {
       where = textmemptr + (ptr_y * width + ptr_x);
       *where = (u16int)(c | att);	/* Character AND attributes: color */
   }
}

void write_string(s8int *text)
{
    s32int i;
    for (i = 0; i < strlen(text); i++)
    {
        write_char((u8int)text[i]);
    }
}

void write_number(u32int num)
{
	if(num < 10)
	{
		write_char(0x30);
	}
	if(num == 0)
	{
		write_char(0x30);
	}

	u32int temp = 0;
	u32int remainder = 0;
	s8int text[11];//longest possible s32integer is 10 digits long + the null terminator
	u32int index = 9;
	u32int i = 0;
	text[10] = 0x00;
	while((num != 0) & (index < 11))
	{
		temp = num / 10;
		remainder = num % 10;
		
		text[index] = (s8int)(remainder + 48);
		index--;

		num = temp;
	}
	index++;
	//shift the letters to the beginning of the array
	for(i = index; i < 11; i++)
	{
		text[i - index] = text[i];
		text[i] = 0x00;
	}
	write_string(text);
} 

void write_hex(u32int num)
{
	u32int tmp;
   s8int noZeroes = 1;
   s32int i;

	write_string("0x");

   for (i = 28; i > 0; i -= 4)
   {
       tmp = (num >> i) & 0xF;
       if (tmp == 0 && noZeroes != 0)
       {
           continue;
       }
    
       if (tmp >= 0xA)
       {
           noZeroes = 0;
           write_char((u8int)(tmp-0xA+'a'));
       }
       else
       {
           noZeroes = 0;
           write_char((u8int)(tmp+'0'));
       }
   }
  
   tmp = num & 0xF;
   if (tmp >= 0xA)
   {
       write_char((u8int)(tmp-0xA+'a'));
   }
   else
   {
       write_char((u8int)(tmp+'0'));
   }
}

/* Sets the forecolor and backcolor that we will use */
void settextcolor(u8int forecolor, u8int backcolor)
{
    /* Top 4 bytes are the background, bottom 4 bytes
    *  are the foreground color */
    attrib = (u32int)((backcolor << 4) | (forecolor & 0x0F));
}

void init_video(void)
{
   textmemptr = (u16int *)0xB8000;
   clear_screen();
}

void set_small_font(void)
{
	s32int line_height = 8;//8 pixels high s8intacters

	outportb(SEQ_ADDR, SEQ_I_RESET);//asynchronously clear and halt.
	outportb(SEQ_DATA, 0x01);

	outportb(SEQ_ADDR, SEQ_I_MAPMASK);
	u8int org_mapmask = inportb(SEQ_DATA);
	outportb(SEQ_DATA, 0x04);	//(0100) select plane 2 (the font plane)

	outportb(SEQ_ADDR, SEQ_I_MEMMODE);
	u8int org_memmode = inportb(SEQ_DATA);
	outportb(SEQ_DATA , 0x07);	//(0010) chain 4 disable, odd even enable, extended mem enable

	outportb(SEQ_ADDR, SEQ_I_CHARMAP);
	outportb(SEQ_DATA, 0x00);	//(000000) font a and b are mapped to zero (the first font)

	outportb(SEQ_ADDR, SEQ_I_RESET);//continue operation
	outportb(SEQ_DATA, 0x03);

	outportb(GFX_ADDR, GFX_I_READMAP); 
	outportb(GFX_DATA, 0x02); 	//read map: 2

	outportb(GFX_ADDR, GFX_I_MODE); 
	outportb(GFX_DATA, 0x00); 	//mode read: 0 mode write: 0

	outportb(GFX_ADDR, GFX_I_MISC); 
	u8int org_gfx = inportb(GFX_DATA);
	outportb(GFX_ADDR, GFX_I_MISC); 
	outportb(GFX_DATA, 0x04); 	//(0000) disable odd/even

	u8int *pVidMem = (u8int*)0xA0000;
	s32int i,j = 0;

	for (i = 0; i < 256; i++)
	{
		for (j = 0; j < line_height; j++)
		{
			*(pVidMem + j) = 0x00;//clear it first
			*(pVidMem + j) = smallfont_thin[i*8+j];//then set the value
		}
		pVidMem += 32;
	}

	outportb(SEQ_ADDR, SEQ_I_RESET);//asynchronously clear and halt.
	outportb(SEQ_DATA, 0x01);

	outportb(SEQ_ADDR, SEQ_I_MEMMODE);
	outportb(SEQ_DATA, org_memmode);

	outportb(SEQ_ADDR, SEQ_I_MAPMASK);
	outportb(SEQ_DATA, org_mapmask);	//(0011) planes 0 and 1

	outportb(SEQ_ADDR, SEQ_I_RESET);//continue operation
	outportb(SEQ_DATA, 0x03);

	outportb(GFX_ADDR, GFX_I_MISC); //restore the old gfx misc settings
	outportb(GFX_DATA, org_gfx);

	outportb(GFX_ADDR, GFX_I_MODE);
	outportb(GFX_DATA, 0x10);//mode: host odd/even

	outportb(GFX_ADDR, GFX_I_BITMASK);
	outportb(GFX_DATA, 0xFF);

	outportb(GFX_ADDR, GFX_I_READMAP); 
	outportb(GFX_DATA, 0x00); 	//read map: 0

	//write_string("fontset\n");
	//wait_key();	

}

void vga_h_resolution(u32int res)
{
	if(!res)
		return;
	//u8int h_s8int_width;
	u8int h_total = 95;//width of a scanline in s8intacters - 5
										//the scanline here is 100 s8intacters wide
	u8int h_end_display = (u8int)(res - 1);//the last s8intacter to be calculated from memory
	u8int h_start_blank = 90;//the last s8intacter before horizontal blanking starts
												//here it is the 90'th s8intacter
	u8int h_end_blank = 35; //99'th s8intacter and'ed with 0x3F
	u8int h_start_retrace = 94;	//the last s8intacter before horizontal retracing starts
													//here it is the 94'th s8intacter
	u8int h_end_retrace = 1; //96'th s8intacter and'ed with 0x1F

	outportb(SEQ_ADDR, SEQ_I_RESET);//asynchronously clear and halt.
	outportb(SEQ_DATA, 0x01);

		outportb(VGA_MISC_W, 0xE7);//set part of the clock data through the misc regester

	outportb(SEQ_ADDR, SEQ_I_RESET);//continue operation
	outportb(SEQ_DATA, 0x03);

	outportb(SEQ_ADDR, SEQ_I_RESET);//synchronously clear and halt
	outportb(SEQ_DATA, 0x02);

		outportb(SEQ_ADDR, SEQ_I_CLOCK);
		outportb(SEQ_DATA, 0x01);//(8 dot wide s8intacters)

	outportb(SEQ_ADDR, SEQ_I_RESET);//continue operation
	outportb(SEQ_DATA, 0x03);

	//write_string("clockset\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_H_TOTAL); 
	outportb(CRT_DATA, h_total);	

	//write_string("CRT_I_H_TOTAL\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_END_H_DIS);
	outportb(CRT_DATA, h_end_display);	

	//write_string("CRT_I_END_H_DIS\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_START_H_BLANK);
	outportb(CRT_DATA, h_start_blank);	

	//write_string("CRT_I_START_H_BLANK\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_END_H_BALNK);
	outportb(CRT_DATA, (u8int)(h_end_blank & 0x0F));

	//write_string("CRT_I_END_H_BALNK\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_START_H_RET);
	outportb(CRT_DATA, h_start_retrace);

	//write_string("CRT_I_START_H_RET\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_END_H_RET);
	outportb(CRT_DATA, (u8int)(((h_end_blank << 2) & 80) | h_end_retrace));

	//write_string("CRT_I_END_H_RET\n");
	//wait_key();	
}

void set80x60(void)
{

	//write_string("Ready...\n");
	//wait_key();

	clear_screen();	

	//write_string("Ready...\n");
	//wait_key();

	set_small_font();	

	vga_h_resolution(80);

	outportb(CRT_ADDR, CRT_I_V_TOTAL); 
	outportb(CRT_DATA, 0x0B);//(0xBF == 191)

	//write_string("CRT_I_V_TOTAL\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_OVERFLOW); 
	outportb(CRT_DATA, 0x3E);//(0x1f)

	//write_string("CRT_I_OVERFLOW\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_PRE_ROW_SCN); 
	outportb(CRT_DATA, 0x00);//(0x00)

	//write_string("CRT_I_PRE_ROW_SCN\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_MAX_SCN_LINE);
	outportb(CRT_DATA, 0x07);//(0x47)

	//write_string("CRT_I_MAX_SCN_LINE\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_START_V_RET);
	outportb(CRT_DATA, 0xEA);//(0x9c)

	//write_string("CRT_I_START_V_RET\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_END_V_RET);
	outportb(CRT_DATA, 0x0C);//(0x8E)

	//write_string("CRT_I_END_V_RET\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_END_V_DIS);
	outportb(CRT_DATA, 0xDF);//(0x8F)

	//write_string("CRT_I_END_V_DIS\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_OFFSET);
	outportb(CRT_DATA, 0x28);//either 0x50 or 0x28

	//write_string("CRT_I_OFFSET\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_UND_LOC);
	outportb(CRT_DATA, 0x1F);//(0x1F)

	//write_string("CRT_I_UND_LOC\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_START_V_BLANK);
	outportb(CRT_DATA, 0xe7);//(0x90)

	//write_string("CRT_I_START_V_BLANK\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_END_V_BLANK);
	outportb(CRT_DATA, 0x04);//(0xb4)

	//write_string("CRT_I_END_V_BLANK\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_MODE);
	outportb(CRT_DATA, 0xE3);//(0xa3)

	//write_string("CRT_I_MODE\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_LINE_CMP);
	outportb(CRT_DATA, 0xFF);//(0xff)

	//write_string("CRT_I_LINE_CMP\n");
	//wait_key();	

	outportb(CRT_ADDR, CRT_I_START_CUR);
	outportb(CRT_DATA, 0x07);

	outportb(CRT_ADDR, CRT_I_END_CUR);
	outportb(CRT_DATA, 0x08);

	width = 80;
	height = 60;
}
